package com.lineage.server.clientpackets;

import com.lineage.echo.ClientExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_FixWeaponList;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C_FixWeaponList extends ClientBasePacket {
  private static final Log _log = LogFactory.getLog(C_FixWeaponList.class);
  
  public void start(byte[] decrypt, ClientExecutor client) {
    try {
      L1PcInstance pc = client.getActiveChar();
      List<L1ItemInstance> weaponList = new ArrayList<>();
      List<L1ItemInstance> itemList = pc.getInventory().getItems();
      Iterator<L1ItemInstance> iterator = itemList.iterator();
      while (iterator.hasNext()) {
        L1ItemInstance item = iterator.next();
        switch (item.getItem().getType2()) {
          case 1:
            if (item.get_durability() <= 0)
              continue; 
            weaponList.add(item);
        } 
      } 
      pc.sendPackets((ServerBasePacket)new S_FixWeaponList(weaponList));
    } catch (Exception exception) {
    
    } finally {
      over();
    } 
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
